﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace register
{
    class DBHelper
    {
        public string sql;
        public static string connStr = "server=.;database=Uesr;uid=sa;pwd=123456";

        public static SqlDataReader Select(string sql)
        {
            //1.创建连接对象
            SqlConnection conn = new SqlConnection(connStr);
            //2.打开链接
            conn.Open();
            //3.创建对象命令
            SqlCommand cmd = new SqlCommand(sql, conn);
            //4.ExecuteReader执行
            return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
        }

        public static bool GetNonQuery(string sql)
        {
            bool res = false;
            //1.创建连接对象
            SqlConnection conn = new SqlConnection(connStr);
            //2.打开链接
            conn.Open();
            //3.创建对象命令
            SqlCommand cmd = new SqlCommand(sql, conn);
            //4.ExecuteReader执行
            int num = cmd.ExecuteNonQuery();
            if (num > 0)
            {
                res = true;
            }
            conn.Close();
            return res;
        }
    }
}
